package com.mak001.lite.multiSkill.GUI.Tabs;

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.rsbuddy.script.wrappers.Area;

public class ChopperTab extends JPanel {
	private static final long serialVersionUID = 1L;

	private JTextField textField12;
	private JComboBox treeDropDown;
	private JTextField textField16;
	private JComboBox cutterPlaces;
	private JCheckBox pc;
	
	String[] trees = { "normal", "oak", "willow" };
	String[] Places = {"......."};

	public ChopperTab() {
		textField16 = new JTextField();
		cutterPlaces = new JComboBox();
		textField12 = new JTextField();
		treeDropDown = new JComboBox();
		pc = new JCheckBox();
		this.setLayout(null);

		// ---- textField12 ----
		textField12.setText("Trees to Cut");
		textField12.setEditable(false);
		textField12.setHorizontalAlignment(SwingConstants.CENTER);
		this.add(textField12);
		textField12.setBounds(130, 30, 130,
				textField12.getPreferredSize().height);

		// ---- treeDropDown ----
		treeDropDown.setModel(new DefaultComboBoxModel(trees));
		treeDropDown.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				placeChange(e);
			}
		});
		this.add(treeDropDown);
		treeDropDown.setBounds(130, 55, 130,
				treeDropDown.getPreferredSize().height);
		
		//---- textField16 ----
		textField16.setText("Places to Cut");
		textField16.setEditable(false);
		textField16.setHorizontalAlignment(SwingConstants.CENTER);
		this.add(textField16);
		textField16.setBounds(190, 30, 160, textField16.getPreferredSize().height);

		//---- cutterPlaces ----
		cutterPlaces.setModel(new DefaultComboBoxModel(Places));
		this.add(cutterPlaces);
		cutterPlaces.setBounds(190, 55, 160, cutterPlaces.getPreferredSize().height);
		
		//---- pc ----
		pc.setText("power chop");
		this.add(pc);
		pc.setBounds(135, 5, 105, pc.getPreferredSize().height);

		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for (int i = 0; i < this.getComponentCount(); i++) {
				Rectangle bounds = this.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width,
						preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height,
						preferredSize.height);
			}
			Insets insets = this.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			this.setMinimumSize(preferredSize);
			this.setPreferredSize(preferredSize);
		}

	}
	
	private void placeChange(ItemEvent e) {
		String s = ((JComboBox) e.getSource()).getSelectedItem().toString();
		cutterPlaces.setModel(new DefaultComboBoxModel(getCutterPlaces(s)));
	}

	private String[] getCutterPlaces(String s) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Area getArea() {
		String s = cutterPlaces.getSelectedItem().toString();
		
		
		return null;
	}

	public int[] getTrees() {
		String s = treeDropDown.getSelectedItem().toString();
			if (s.contains("normal")) {
				return new int[] { 5004, 5005, 5045, 3879, 3881, 3882, 3883, 3885,
						3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967,
						3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034,
						3035, 3036, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304,
						1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973,
						8974, 1315, 1316 };
			} else if (s.contains("oak")) {
				return new int[] { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 };
			} else {// willow
				return new int[] { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484,
						8485, 8486, 8487, 8488 };
			}
	}

	public String getTreeName() {
		return treeDropDown.getSelectedItem().toString();
	}

	public boolean getDrop() {
		return pc.isSelected();
	}

}
